<!--
  - Copyright 2011 Angel Sanadinov
  -
  - This file is part of VBox WMI.
  -
  - VBox WMI is free software: you can redistribute it and/or modify
  - it under the terms of the GNU General Public License as published by
  - the Free Software Foundation, either version 3 of the License, or
  - (at your option) any later version.
  -
  - VBox WMI is distributed in the hope that it will be useful,
  - but WITHOUT ANY WARRANTY; without even the implied warranty of
  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  - GNU General Public License for more details.
  -
  - You should have received a copy of the GNU General Public License
  - along with VBox WMI.  If not, see <http://www.gnu.org/licenses/>.
  -->

<%@tag import="org.virtualbox_3_2.MachineState"%>
<%@tag import="Beans.Responses.DataRetrievalComponents.MachineDataComponent"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="jstlc" %>
<%@tag description="Prints available machine operations, based on the current machine state." pageEncoding="UTF-8" trimDirectiveWhitespaces="true"%>

<%-- Attributes --%>
<%@attribute name="machine" required="true" description="A virtual machine's data object."
             rtexprvalue="true" type="MachineDataComponent"%>
<%-- End of Attributes --%>

<%-- Page Body Content --%>
<div class="operationsElement">
<jstlc:choose>
    <%-- Available operations for machines in POWERED_OFF / SAVED / TELEPORTED / ABORTED state --%>
    <jstlc:when test="<%= machine.getMachineState() == MachineState.POWERED_OFF
                          || machine.getMachineState() == MachineState.SAVED
                          || machine.getMachineState() == MachineState.TELEPORTED
                          || machine.getMachineState() == MachineState.ABORTED %>">
        <a title="Power Up" href="manage_machine.jsp?action=2&amp;state=1&amp;id=${machine.machineData.resourceId}">
            <img src="images/powerUp_resume.png" alt="Power UP"></a>
    </jstlc:when>

    <%-- Available operations for machines in PAUSED state --%>
    <jstlc:when test="<%= machine.getMachineState() == MachineState.PAUSED %>">
        <a title="Resume" href="manage_machine.jsp?action=2&amp;state=6&amp;id=${machine.machineData.resourceId}">
            <img src="images/powerUp_resume.png" alt="Resume"></a>
        <a title="Save" href="manage_machine.jsp?action=2&amp;state=5&amp;id=${machine.machineData.resourceId}">
            <img src="images/save.png" alt="Save"></a>
        <a title="Power Down" href="manage_machine.jsp?action=2&amp;state=2&amp;id=${machine.machineData.resourceId}">
            <img src="images/powerDown.png" ald="Power Down"></a>
    </jstlc:when>

    <%-- Available operations for machines in RUNNING state --%>
    <jstlc:when test="<%= machine.getMachineState() == MachineState.RUNNING || machine.getMachineState() == MachineState.LIVE_SNAPSHOTTING %>">
        <a title="Power Down" href="manage_machine.jsp?action=2&amp;state=2&amp;id=${machine.machineData.resourceId}">
            <img src="images/powerDown.png" alt="Power Down"></a>
        <a title="Reset" href="manage_machine.jsp?action=2&amp;state=3&amp;id=${machine.machineData.resourceId}">
            <img src="images/reset.png" alt="Reset"></a>
        <a title="Pause" href="manage_machine.jsp?action=2&amp;state=4&amp;id=${machine.machineData.resourceId}">
            <img src="images/pause.png" alt="Pause"></a>
        <a title="Save" href="manage_machine.jsp?action=2&amp;state=5&amp;id=${machine.machineData.resourceId}">
            <img src="images/save.png" alt="Save"></a>
        <a title="ACPI Sleep" href="manage_machine.jsp?action=2&amp;state=8&amp;id=${machine.machineData.resourceId}">
            <img height="14" width="14" src="images/acpi_sleep.png" alt="ACPI Sleep"></a>
        <a title="ACPI Off" href="manage_machine.jsp?action=2&amp;state=7&amp;id=${machine.machineData.resourceId}">
            <img height="14" width="14" src="images/acpi_power.png" alt="ACPI Power"></a>
        <a title="Open Console" href="webRDP.jsp?id=${machine.machineData.resourceId}">
            <img src="images/rdp.png" alt="Console"></a>
    </jstlc:when>

    <%-- Available operations for machines in STUCK state --%>
    <jstlc:when test="<%= machine.getMachineState() == MachineState.STUCK %>">
        <a title="Power Down" href="manage_machine.jsp?action=2&amp;state=2&amp;id=${machine.machineData.resourceId}">
            <img src="images/powerDown.png" alt="Power Down"></a>
    </jstlc:when>

    <%-- Available operations for machines in TELEPORTING state --%>
    <jstlc:when test="<%= machine.getMachineState() == MachineState.TELEPORTING %>">
        <a title="Pause" href="manage_machine.jsp?action=2&amp;state=4&iamp;d=${machine.machineData.resourceId}">
            <img src="images/pause.png" alt="Pause"></a>
    </jstlc:when>

    <jstlc:otherwise>
        <a title="Wait..." href=""><img src="images/wait.png" alt="Waiting"></a>
    </jstlc:otherwise>
</jstlc:choose>
</div>
<%-- End of Page Body Content --%>